/*  JFramePrincipal.java
 *  Copyright (C) 2009  Tiago Silva Loureiro
 *  This File is part of Bier Manager.
 *  Bier Manager a is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/*  JFramePrincipal.java - Bier Manager
 *
 *  Tela principal do Bier Manager. Contém o menu principal e o
 *  DesktopPane em que todas as subTelas são operadas pelo usuário.
 * 
 *  @author Tiago Silva Loureiro
 * *
 */

package biermanager.interfaceGrafica;

import biermanager.nucleo.ConstantesDeCaminho;
import biermanager.nucleo.ConstantesDeErro;
import biermanager.nucleo.ConstantesDeJogo;
import biermanager.nucleo.Conta;
import biermanager.nucleo.Temporada;
import biermanager.nucleo.Usuario;
import biermanager.componentes.Cores;
import biermanager.componentes.Eventos;
import biermanager.componentes.PainelMenu;
import biermanager.componentes.PintorDeBackground;
import com.sun.crypto.provider.DESKeyFactory;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsEnvironment;
import java.awt.PopupMenu;
import java.awt.Toolkit;
import java.awt.event.ItemEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.ButtonModel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.jdesktop.swingx.JXButton;
import org.jdesktop.swingx.JXLabel;
import org.jdesktop.swingx.painter.Painter;

public class JFramePrincipal extends javax.swing.JFrame {

    private Conta conta;
    private JInternalFrameIniciarJogo telaIniciarJogo;
    private JInternalFrameCriarNovoJogo telaCriarNovoJogo;
    private JInternalFrameRodada rodada;
    private JInternalFrameSelecionarTime telaDeSelecionarTime;
    private JInternalFrameSortearCampeonato telaDeSorteio;
    private Dimension tamanhoDoDisplay;
    private PintorDeBackground pintorDeBackground;
    private Font trueTypeRabiscos;
    private Font trueTypeArcade;
    private float alpha;

    /** Construtor do FramePrincipal
     *
     *  Funções: Iniciar componentes,
     *  Configurar LookAndFeel,
     *  Obter dimensão do display do usuário,
     *  Registrar fontes utilizadas ao ambiente gráfico local e
     *  Configurar as mensagens padrão da interface ao usuário.
     *
     */
    public JFramePrincipal() {
        //iniciarLookAndFeelDoSistema();
        initComponents();
        iniciarDisplay();
        iniciarBackgrounds();
        iniciarIdioma();
        iniciarFontes();
        configurarNovasFontes();
    }

    private void iniciarLookAndFeelDoSistema() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception e) {
            System.err.println( ConstantesDeErro.lookAndFeelDoSistemaNaoSuportado + e.getMessage() );
        }
    }
    private void iniciarDisplay() {
        tamanhoDoDisplay = Toolkit.getDefaultToolkit().getScreenSize();
        this.setSize(tamanhoDoDisplay);
        this.setResizable(false);
        this.setExtendedState(MAXIMIZED_BOTH);
        painelEstrutural.setSize(tamanhoDoDisplay);
        painelEstruturalDesktop.setSize(tamanhoDoDisplay);
        painelTopo.setSize(this.getWidth(), painelTopo.getHeight());
        painelMenu.setSize(this.getWidth(), painelMenu.getHeight());
        painelDesktop.setSize(this.getWidth(), (int) (tamanhoDoDisplay.height - painelTopo.getPreferredSize().getHeight() - painelMenu.getPreferredSize().getHeight()));
    }
    @SuppressWarnings("unchecked")
    private void iniciarBackgrounds(){
        pintorDeBackground = new PintorDeBackground();
        painelTopo.setBackgroundPainter(pintorDeBackground.pintarPainelTopo(painelTopo,ConstantesDeCaminho.logoBier));
        painelMenu.setBackgroundPainter(pintorDeBackground.pintarPainelMenu(painelMenu));
        painelImagemFundo.setBackgroundPainter(pintorDeBackground.pintorPainelImagem(painelImagemFundo, ConstantesDeCaminho.ImagemBierManager));
        jxlabelIniciarJogo.setBackgroundPainter(pintorDeBackground.pintorIcone(ConstantesDeCaminho.iniciarJogo,100,100));
        jxlabelCriarNovoJogo.setBackgroundPainter(pintorDeBackground.pintorIcone(ConstantesDeCaminho.novoJogo,100,100));
        jxlabelConfigurarJogo.setBackgroundPainter(pintorDeBackground.pintorIcone(ConstantesDeCaminho.configurarJogo,100,100));
        jxlabelModoMultiplayer.setBackgroundPainter(pintorDeBackground.pintorIcone(ConstantesDeCaminho.multiplayer,100,100));
        jxlabelFinalizar.setBackgroundPainter(pintorDeBackground.pintorIcone(ConstantesDeCaminho.finalizar,100,100));
        jxbutttonMenu.setBackgroundPainter((Painter<JXButton>)pintorDeBackground.pintorIcone(ConstantesDeCaminho.menuInicial, 30, 30));
    }

    private void iniciarIdioma(){
        UIManager.put("OptionPane.yesButtonText", "Sim");
        UIManager.put("OptionPane.cancelButtonText", "Cancelar");
        UIManager.put("OptionPane.noButtonText", "Não");
        UIManager.put("OptionPane.okButtonText", "OK");
    }

    private void iniciarFontes(){
        trueTypeRabiscos = null;
        trueTypeArcade = null;
        try {
            trueTypeRabiscos = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream("biermanager/fontes/rabiscos.ttf"));
            trueTypeArcade   = Font.createFont(Font.TRUETYPE_FONT, getClass().getClassLoader().getResourceAsStream("biermanager/fontes/arcade.ttf"));
        } catch (FontFormatException ex) {
            System.err.println( ConstantesDeErro.formatoDaFonteNaoSuportado + ex.getMessage() );
            trueTypeRabiscos = new Font("Tahoma",Font.PLAIN,15);
        } catch (IOException ex) {
            System.err.println( ConstantesDeErro.arquivoAcessoNegado + ex.getMessage() );
            trueTypeRabiscos = new Font("Tahoma",Font.PLAIN,15);
        }
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(trueTypeRabiscos);
    }

    private void configurarNovasFontes(){
        Font fonteSis = new Font(trueTypeArcade.getFontName(), Font.PLAIN, 16);
        Color corDoTexto = Cores.branco;
        jxlabelIniciarJogo.setFont(fonteSis);
        jxlabelCriarNovoJogo.setFont(fonteSis);
        jxlabelConfigurarJogo.setFont(fonteSis);
        jxlabelModoMultiplayer.setFont(fonteSis);
        jxlabelFinalizar.setFont(fonteSis);
        jxbutttonMenu.setFont(fonteSis);
        jxlabelIniciarJogo.setForeground(corDoTexto);
        jxlabelCriarNovoJogo.setForeground(corDoTexto);
        jxlabelConfigurarJogo.setForeground(corDoTexto);
        jxlabelModoMultiplayer.setForeground(corDoTexto);
        jxlabelFinalizar.setForeground(corDoTexto);
        jxbutttonMenu.setForeground(corDoTexto);
    }

    /**
     * Gerado automaticamente pelo matisse(Editor visual do NetBeans).
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        painelEstrutural = new javax.swing.JPanel();
        painelEstruturalDesktop = new org.jdesktop.swingx.JXPanel();
        painelImagemFundo = new org.jdesktop.swingx.JXPanel();
        painelMenu = new biermanager.componentes.PainelMenu();
        painelInvisivel = new org.jdesktop.swingx.JXPanel();
        jxlabelIniciarJogo = new org.jdesktop.swingx.JXLabel();
        jxlabelCriarNovoJogo = new org.jdesktop.swingx.JXLabel();
        jxlabelConfigurarJogo = new org.jdesktop.swingx.JXLabel();
        jxlabelModoMultiplayer = new org.jdesktop.swingx.JXLabel();
        jxlabelFinalizar = new org.jdesktop.swingx.JXLabel();
        painelDesktop = new javax.swing.JDesktopPane();
        painelTopo = new biermanager.componentes.PainelTopo();
        jxbutttonMenu = new org.jdesktop.swingx.JXButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Bier Manager 2008");
        setBackground(new java.awt.Color(255, 255, 255));
        setBounds(new java.awt.Rectangle(0, 0, 0, 0));
        setIconImage(Toolkit.getDefaultToolkit().getImage("bierico.gif"));
        setName("telaPrincipal"); // NOI18N
        setResizable(false);
        setUndecorated(true);

        painelEstruturalDesktop.setAlpha(0.25f);
        painelEstruturalDesktop.setMinimumSize(new java.awt.Dimension(800, 600));
        painelEstruturalDesktop.setPreferredSize(new java.awt.Dimension(745, 585));
        painelEstruturalDesktop.setScrollableTracksViewportHeight(false);
        painelEstruturalDesktop.setScrollableTracksViewportWidth(false);

        painelImagemFundo.setInheritAlpha(false);
        painelImagemFundo.setOpaque(false);

        painelMenu.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), javax.swing.BorderFactory.createLineBorder(new java.awt.Color(9, 9, 9))));
        painelMenu.setInheritAlpha(false);
        painelMenu.setOpaque(false);
        painelMenu.setAlignmentX(0.0F);
        painelMenu.setAlignmentY(0.0F);
        painelMenu.setFocusable(false);

        painelInvisivel.setBackground(new java.awt.Color(255, 0, 0));
        painelInvisivel.setInheritAlpha(false);
        painelInvisivel.setOpaque(false);
        painelInvisivel.setPreferredSize(new java.awt.Dimension(796, 306));

        jxlabelIniciarJogo.setForeground(new java.awt.Color(255, 255, 255));
        jxlabelIniciarJogo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jxlabelIniciarJogo.setText("Iniciar Jogo");
        jxlabelIniciarJogo.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jxlabelIniciarJogo.setFont(new java.awt.Font("Tahoma", 1, 14));
        jxlabelIniciarJogo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jxlabelIniciarJogo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jxlabelIniciarJogoMouseClicked(evt);
                MenuLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jxlabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jxlabelMouseExtd(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jxlabelIniciarJogoMouseReleased(evt);
            }
        });

        jxlabelCriarNovoJogo.setForeground(new java.awt.Color(255, 255, 255));
        jxlabelCriarNovoJogo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jxlabelCriarNovoJogo.setText("Criar Novo Jogo");
        jxlabelCriarNovoJogo.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jxlabelCriarNovoJogo.setFont(new java.awt.Font("Tahoma", 1, 14));
        jxlabelCriarNovoJogo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jxlabelCriarNovoJogo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jxlabelCriarNovoJogoMouseClicked(evt);
                MenuLabelMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jxlabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jxlabelMouseExtd(evt);
            }
        });

        jxlabelConfigurarJogo.setForeground(new java.awt.Color(255, 255, 255));
        jxlabelConfigurarJogo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jxlabelConfigurarJogo.setText("Configurar Jogo");
        jxlabelConfigurarJogo.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jxlabelConfigurarJogo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jxlabelConfigurarJogo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jxlabelConfigurarJogo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jxlabelConfigurarJogoMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jxlabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jxlabelMouseExtd(evt);
            }
        });

        jxlabelModoMultiplayer.setForeground(new java.awt.Color(255, 255, 255));
        jxlabelModoMultiplayer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jxlabelModoMultiplayer.setText("Multijogador");
        jxlabelModoMultiplayer.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jxlabelModoMultiplayer.setFont(new java.awt.Font("Tahoma", 1, 14));
        jxlabelModoMultiplayer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jxlabelModoMultiplayer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jxlabelModoMultiplayerMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jxlabelModoMultiplayerjxlabelMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jxlabelModoMultiplayerjxlabelMouseExtd(evt);
            }
        });

        jxlabelFinalizar.setForeground(new java.awt.Color(255, 255, 255));
        jxlabelFinalizar.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jxlabelFinalizar.setText("X  -  Sair");
        jxlabelFinalizar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jxlabelFinalizar.setFont(new java.awt.Font("Tahoma", 1, 14));
        jxlabelFinalizar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jxlabelFinalizar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jxlabelFinalizarMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jxlabelFinalizarJogoMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                jxlabelFinalizarMouseExited(evt);
            }
        });

        javax.swing.GroupLayout painelInvisivelLayout = new javax.swing.GroupLayout(painelInvisivel);
        painelInvisivel.setLayout(painelInvisivelLayout);
        painelInvisivelLayout.setHorizontalGroup(
            painelInvisivelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelInvisivelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jxlabelIniciarJogo, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxlabelCriarNovoJogo, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxlabelConfigurarJogo, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxlabelModoMultiplayer, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jxlabelFinalizar, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                .addContainerGap())
        );
        painelInvisivelLayout.setVerticalGroup(
            painelInvisivelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelInvisivelLayout.createSequentialGroup()
                .addGap(82, 82, 82)
                .addGroup(painelInvisivelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxlabelCriarNovoJogo, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxlabelFinalizar, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxlabelConfigurarJogo, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxlabelModoMultiplayer, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxlabelIniciarJogo, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(74, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout painelMenuLayout = new javax.swing.GroupLayout(painelMenu);
        painelMenu.setLayout(painelMenuLayout);
        painelMenuLayout.setHorizontalGroup(
            painelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelInvisivel, javax.swing.GroupLayout.DEFAULT_SIZE, 931, Short.MAX_VALUE)
        );
        painelMenuLayout.setVerticalGroup(
            painelMenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelInvisivel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout painelImagemFundoLayout = new javax.swing.GroupLayout(painelImagemFundo);
        painelImagemFundo.setLayout(painelImagemFundoLayout);
        painelImagemFundoLayout.setHorizontalGroup(
            painelImagemFundoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        painelImagemFundoLayout.setVerticalGroup(
            painelImagemFundoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelImagemFundoLayout.createSequentialGroup()
                .addComponent(painelMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(293, Short.MAX_VALUE))
        );

        painelDesktop.setBackground(new java.awt.Color(250, 242, 241));
        painelDesktop.setAlignmentX(0.0F);
        painelDesktop.setAlignmentY(0.0F);
        painelDesktop.setDragMode(javax.swing.JDesktopPane.OUTLINE_DRAG_MODE);
        painelDesktop.setOpaque(false);

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${preferredSize.size}"), painelDesktop, org.jdesktop.beansbinding.BeanProperty.create("preferredSize"));
        bindingGroup.addBinding(binding);

        javax.swing.GroupLayout painelEstruturalDesktopLayout = new javax.swing.GroupLayout(painelEstruturalDesktop);
        painelEstruturalDesktop.setLayout(painelEstruturalDesktopLayout);
        painelEstruturalDesktopLayout.setHorizontalGroup(
            painelEstruturalDesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 935, Short.MAX_VALUE)
            .addGroup(painelEstruturalDesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(painelImagemFundo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        painelEstruturalDesktopLayout.setVerticalGroup(
            painelEstruturalDesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelDesktop, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
            .addGroup(painelEstruturalDesktopLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(painelImagemFundo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        painelTopo.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))));
        painelTopo.setAlignmentX(0.0F);
        painelTopo.setAlignmentY(0.0F);
        painelTopo.setFocusable(false);
        painelTopo.setPreferredSize(new java.awt.Dimension(400, 100));
        painelTopo.setRequestFocusEnabled(false);

        jxbutttonMenu.setBorder(null);
        jxbutttonMenu.setForeground(new java.awt.Color(255, 255, 255));
        jxbutttonMenu.setContentAreaFilled(false);
        jxbutttonMenu.setFocusPainted(false);
        jxbutttonMenu.setFocusable(false);
        jxbutttonMenu.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jxbutttonMenu.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
        jxbutttonMenu.setRequestFocusEnabled(false);
        jxbutttonMenu.setSelected(true);
        jxbutttonMenu.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jxbutttonMenu.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jxbutttonMenu.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jxbutttonMenuStateChanged(evt);
            }
        });
        jxbutttonMenu.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxbutttonMenuItemStateChanged(evt);
            }
        });
        jxbutttonMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxbutttonMenuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout painelTopoLayout = new javax.swing.GroupLayout(painelTopo);
        painelTopo.setLayout(painelTopoLayout);
        painelTopoLayout.setHorizontalGroup(
            painelTopoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelTopoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jxbutttonMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(881, Short.MAX_VALUE))
        );
        painelTopoLayout.setVerticalGroup(
            painelTopoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelTopoLayout.createSequentialGroup()
                .addContainerGap(53, Short.MAX_VALUE)
                .addComponent(jxbutttonMenu, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout painelEstruturalLayout = new javax.swing.GroupLayout(painelEstrutural);
        painelEstrutural.setLayout(painelEstruturalLayout);
        painelEstruturalLayout.setHorizontalGroup(
            painelEstruturalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 935, Short.MAX_VALUE)
            .addGroup(painelEstruturalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(painelTopo, javax.swing.GroupLayout.DEFAULT_SIZE, 935, Short.MAX_VALUE))
            .addGroup(painelEstruturalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(painelEstruturalDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 935, Short.MAX_VALUE))
        );
        painelEstruturalLayout.setVerticalGroup(
            painelEstruturalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 703, Short.MAX_VALUE)
            .addGroup(painelEstruturalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(painelEstruturalLayout.createSequentialGroup()
                    .addComponent(painelTopo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(603, Short.MAX_VALUE)))
            .addGroup(painelEstruturalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelEstruturalLayout.createSequentialGroup()
                    .addGap(100, 100, 100)
                    .addComponent(painelEstruturalDesktop, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelEstrutural, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelEstrutural, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jxbutttonMenuStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jxbutttonMenuStateChanged
        // TODO add your handling code here:
}//GEN-LAST:event_jxbutttonMenuStateChanged

    private void jxbutttonMenuItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxbutttonMenuItemStateChanged
        if (evt.getStateChange() == ItemEvent.SELECTED) 
            mostrarMenu();
        else 
            esconderMenu();
        
}//GEN-LAST:event_jxbutttonMenuItemStateChanged

    private void jxbutttonMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxbutttonMenuActionPerformed
        if (jxbutttonMenu.isSelected()) {
            jxbutttonMenu.setSelected(false);
            if(painelDesktop.getSelectedFrame() != null)
                try {
                painelDesktop.getSelectedFrame().setIcon(false);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(JFramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            jxbutttonMenu.setSelected(true);
            try {
                if(painelDesktop.getSelectedFrame() != null)
                    painelDesktop.getSelectedFrame().setIcon(true);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(JFramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

}//GEN-LAST:event_jxbutttonMenuActionPerformed

    private void jxlabelFinalizarMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelFinalizarMouseExited
        Eventos.mouseSaiBotaoMenuPrincipal(evt);
}//GEN-LAST:event_jxlabelFinalizarMouseExited

    private void jxlabelFinalizarJogoMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelFinalizarJogoMouseEntered
        Eventos.mouseEntraBotaoMenuPrincipal(evt);
        JXLabel jxl = (JXLabel) evt.getSource();
        jxl.setForeground(new Color(235, 0, 0));
}//GEN-LAST:event_jxlabelFinalizarJogoMouseEntered

    private void jxlabelFinalizarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelFinalizarMouseClicked
        if (JOptionPane.showConfirmDialog(null, ConstantesDeJogo.desejaFinalizar, ConstantesDeJogo.tituloDoJogo , JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION) {
            System.exit(0);
        }
}//GEN-LAST:event_jxlabelFinalizarMouseClicked

    private void jxlabelModoMultiplayerjxlabelMouseExtd(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelModoMultiplayerjxlabelMouseExtd
        Eventos.mouseSaiBotaoMenuPrincipal(evt);
}//GEN-LAST:event_jxlabelModoMultiplayerjxlabelMouseExtd

    private void jxlabelModoMultiplayerjxlabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelModoMultiplayerjxlabelMouseEntered
        Eventos.mouseEntraBotaoMenuPrincipal(evt);
}//GEN-LAST:event_jxlabelModoMultiplayerjxlabelMouseEntered

    private void jxlabelModoMultiplayerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelModoMultiplayerMouseClicked
        // TODO add your handling code here:
}//GEN-LAST:event_jxlabelModoMultiplayerMouseClicked

    private void jxlabelMouseExtd(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelMouseExtd
        Eventos.mouseSaiBotaoMenuPrincipal(evt);
}//GEN-LAST:event_jxlabelMouseExtd

    private void jxlabelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelMouseEntered
        Eventos.mouseEntraBotaoMenuPrincipal(evt);
}//GEN-LAST:event_jxlabelMouseEntered

    private void jxlabelConfigurarJogoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelConfigurarJogoMouseClicked
        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        painelDesktop.removeAll();
        painelDesktop.repaint();
        Eventos.mouseSaiBotaoMenuPrincipal(evt);
        esconderMenu();
        conta = new Conta(new Usuario(""));
        rodada = new JInternalFrameRodada(conta,painelDesktop.getSize());
        rodada.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        painelImagemFundo.setBackgroundPainter(pintorDeBackground.pintorPainelImagem(painelImagemFundo, ConstantesDeCaminho.imagemFutsal));
        painelDesktop.add(rodada);
        rodada.addPropertyChangeListener(ouvinteInternalFrameRodada);
        rodada.setVisible(true);
        this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}//GEN-LAST:event_jxlabelConfigurarJogoMouseClicked

    private void jxlabelCriarNovoJogoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelCriarNovoJogoMouseClicked
        painelDesktop.removeAll();
        painelDesktop.repaint();
        telaCriarNovoJogo = new JInternalFrameCriarNovoJogo();
        painelDesktop.add(telaCriarNovoJogo);
        telaCriarNovoJogo.addPropertyChangeListener(ouvinteInternalFrameCriarNovoJogo);
        telaCriarNovoJogo.setVisible(true);
        Eventos.mouseSaiBotaoMenuPrincipal(evt);
        esconderMenu();
}//GEN-LAST:event_jxlabelCriarNovoJogoMouseClicked

    private void MenuLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_MenuLabelMouseClicked
        JXLabel jxl = (JXLabel) evt.getSource();
        jxl.setForeground(new Color(255, 240, 35));
}//GEN-LAST:event_MenuLabelMouseClicked

    private void jxlabelIniciarJogoMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelIniciarJogoMouseReleased
        painelDesktop.removeAll();
        painelDesktop.repaint();
        telaIniciarJogo = new JInternalFrameIniciarJogo();
        painelDesktop.add(telaIniciarJogo);
        telaIniciarJogo.addPropertyChangeListener(ouvinteInternalFrameIniciarJogo);
        telaIniciarJogo.setVisible(true);
        Eventos.mouseSaiBotaoMenuPrincipal(evt);
        esconderMenu();
}//GEN-LAST:event_jxlabelIniciarJogoMouseReleased

    private void jxlabelIniciarJogoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jxlabelIniciarJogoMouseClicked
      /*  painelDesktop.removeAll();
        painelDesktop.repaint();
        telaIniciarJogo = new JInternalFrameIniciarJogo();
        painelDesktop.add(telaIniciarJogo);
        telaIniciarJogo.addPropertyChangeListener(ouvinteInternalFrameIniciarJogo);
        telaIniciarJogo.setVisible(true); */
}//GEN-LAST:event_jxlabelIniciarJogoMouseClicked
        @SuppressWarnings("unchecked")
    private void mostrarMenu() {
        painelImagemFundo.add(painelMenu);
        javax.swing.GroupLayout painelImagemFundoLayout = new javax.swing.GroupLayout(painelImagemFundo);
        painelImagemFundo.setLayout(painelImagemFundoLayout);
        painelImagemFundoLayout.setHorizontalGroup(
            painelImagemFundoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(painelMenu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        painelImagemFundoLayout.setVerticalGroup(
            painelImagemFundoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelImagemFundoLayout.createSequentialGroup()
                .addComponent(painelMenu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(560, Short.MAX_VALUE))
        );
            alpha = 0.f;
    final Timer tempo = new Timer();            //Temporizador
    TimerTask tarefa = new TimerTask() {     //Objeto tarefa a ser realizada
        public void run() {                 //Metodo run que implementa a tarefa
            if ((alpha + 0.1) <= 1.0f) {
                alpha = alpha + 0.1f;
                PintorDeBackground p = new PintorDeBackground();
                painelMenu.setSize(painelMenu.getWidth(),painelMenu.getHeight() );
            } else {
                tempo.cancel();
            }
            painelMenu.setAlpha(alpha);
            painelInvisivel.setAlpha(alpha);
        }
    };
            tempo.schedule(tarefa, 50, 50);
            jxbutttonMenu.setSelected(true);
            //jxbutttonMenu.setBackgroundPainter(pintorDeBackground.pintorIcone(ConstantesDeCaminho.minimizarMenu, 50, 50));
            //jxbutttonMenu.setText("Minimizar Menu");
            configurarNovasFontes();
    }

                @SuppressWarnings("unchecked")
    private void esconderMenu(){
    alpha = 1.f;
    final Timer tempo = new Timer();            //Temporizador
    TimerTask tarefa = new TimerTask() {     //Objeto tarefa a ser realizada
        public void run() {                 //Metodo run que implementa a tarefa
            if ((alpha - 0.1) >= 0.f) {
                alpha = alpha - 0.1f;
            } else {
                tempo.cancel();
                painelImagemFundo.remove(painelMenu);
                painelImagemFundo.repaint();
            }
            painelMenu.setAlpha(alpha);
            painelInvisivel.setAlpha(alpha);
        }
    };
            tempo.schedule(tarefa, 50, 50);
            jxbutttonMenu.setSelected(false);
            //jxbutttonMenu.setBackgroundPainter(pintorDeBackground.pintorIcone(ConstantesDeCaminho.expandirMenu, 50, 50));
            //jxbutttonMenu.setText("Expandir Menu");
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXButton jxbutttonMenu;
    private org.jdesktop.swingx.JXLabel jxlabelConfigurarJogo;
    private org.jdesktop.swingx.JXLabel jxlabelCriarNovoJogo;
    private org.jdesktop.swingx.JXLabel jxlabelFinalizar;
    private org.jdesktop.swingx.JXLabel jxlabelIniciarJogo;
    private org.jdesktop.swingx.JXLabel jxlabelModoMultiplayer;
    private javax.swing.JDesktopPane painelDesktop;
    private javax.swing.JPanel painelEstrutural;
    private org.jdesktop.swingx.JXPanel painelEstruturalDesktop;
    private org.jdesktop.swingx.JXPanel painelImagemFundo;
    private org.jdesktop.swingx.JXPanel painelInvisivel;
    private biermanager.componentes.PainelMenu painelMenu;
    private biermanager.componentes.PainelTopo painelTopo;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    
    private PropertyChangeListener ouvinteInternalFrameIniciarJogo = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if ("Iniciar".equals(evt.getPropertyName())) {
                telaIniciarJogo.dispose();
                rodada = new JInternalFrameRodada(conta,painelDesktop.getSize());
                painelDesktop.add(rodada);
                rodada.setVisible(true);
            }
            if ("Fechar".equals(evt.getPropertyName())) {
                painelDesktop.remove(telaIniciarJogo);
                painelDesktop.repaint();
                mostrarMenu();
            }
        }
    };
    
    private PropertyChangeListener ouvinteInternalFrameCriarNovoJogo = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if ("Continuar".equals(evt.getPropertyName())) {
                conta = (Conta) evt.getNewValue();
                telaDeSelecionarTime = new JInternalFrameSelecionarTime(conta);
                painelDesktop.add(telaDeSelecionarTime);
                telaDeSelecionarTime.addPropertyChangeListener(ouvinteInternalFrameSelecionarTime);
                esconderMenu();
                telaDeSelecionarTime.setVisible(true);
                telaCriarNovoJogo.dispose();
            }
            if ("Fechar".equals(evt.getPropertyName())) {
                painelDesktop.remove(telaCriarNovoJogo);
                painelDesktop.repaint();
                mostrarMenu();
            }
        }
    };

    private PropertyChangeListener ouvinteInternalFrameSelecionarTime = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            
            if ("Continuar".equals(evt.getPropertyName())) {
                painelDesktop.remove(telaDeSelecionarTime);
                painelDesktop.repaint();
                conta = (Conta) evt.getNewValue();
                telaDeSorteio = new JInternalFrameSortearCampeonato(conta.getTimes(), 0);
                painelDesktop.add(telaDeSorteio);
                telaDeSorteio.addPropertyChangeListener(ouvinteInternalFrameSortearCampeonato);
                telaDeSorteio.setVisible(true);
            }
            if ("Fechar".equals(evt.getPropertyName())) {
                painelDesktop.remove(telaDeSelecionarTime);
                painelDesktop.repaint();
                mostrarMenu();
            }
        }
    };
    
    private PropertyChangeListener ouvinteInternalFrameSortearCampeonato = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evte) {
            if ("Iniciar Jogo".equals(evte.getPropertyName())) {
                conta.addObjeto((Temporada)evte.getNewValue());
                painelDesktop.remove(telaDeSorteio);
                painelDesktop.repaint();
                rodada = new JInternalFrameRodada(conta, painelDesktop.getSize());
                painelDesktop.add(rodada);
                rodada.setVisible(true);
            }
            }
        
    };
private PropertyChangeListener ouvinteInternalFrameRodada = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evte) {
            if ("Carregado".equals(evte.getPropertyName())) {
                rodada.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

            }
            }        
    };
}
